package com.xpf.shardingtabledemo.controller;

import com.xpf.shardingtabledemo.dao.OperationpersonLogDao;
import com.xpf.shardingtabledemo.dbqueryext.AutoCreateTableSchedule;
import com.xpf.shardingtabledemo.entity.OperationpersonLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.LinkedList;
import java.util.List;

/**
 * 测试生成表
 * @Author xpf
 * @Date 2023/10/9 11:03
 * @Version 1.0
 */
@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    private AutoCreateTableSchedule autoCreateTableSchedule;

    @Autowired
    private OperationpersonLogDao operationpersonLogDao;

    @RequestMapping("/start")
    public void start(){
        autoCreateTableSchedule.AutoCreateTable();
    }

    @RequestMapping("/insert")
    public String insertTable(){
        List<OperationpersonLog> opList = new LinkedList<>();
        OperationpersonLog operationpersonLog = new OperationpersonLog();
        operationpersonLog.setAge(11);
        operationpersonLog.setName("依依");
        opList.add(operationpersonLog);

        operationpersonLogDao.insert(operationpersonLog);

        operationpersonLog.setAge(22);
        operationpersonLog.setName("谔谔");
        opList.add(operationpersonLog);

        operationpersonLog.setAge(33);
        operationpersonLog.setName("叁叁");
        opList.add(operationpersonLog);
//       operationpersonLogDao.insertBatch(opList);
        return "success";
    }

    @RequestMapping("/select")
    public OperationpersonLog selectTable(){
        return operationpersonLogDao.queryById(1);
    }

}
